<template>
  <div class="">
    <input
      type="text"
      :value="modelValue"
      @input="inpChange"
      @keydown.enter="add"
    />
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, reactive, toRefs } from "vue";
import { useStore } from "vuex";
import { useRouter, useRoute } from "vue-router";
export default defineComponent({
  props: {
    modelValue: String,
  },
  setup(props, ctx) {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
    const data = reactive({});
    // const inpChange = (e): void => {
    //   ctx.emit("update:modelValue", e.target.value);
    // };
    //也能出效果

    const inpChange = (e: Event): void => {
      console.log(e);

      ctx.emit("update:modelValue", (<HTMLInputElement>e.target).value);
    };
    // e: Event 参数e的数据类型是Event  Event是内置的一个接口
    // (<HTMLInputElement>e.target) 给e.target 给目标dom节点 也指定一个数据类型 是input元素

    const add = () => {
      //   console.log(111);

      ctx.emit("enter");
    };
    //按下回车的时候 调用父组件的enter添加方法

    return { ...toRefs(data), inpChange, add };
  },
});
</script>

<style lang="scss"></style>
